<template>
<div>
  <Row type="flex" :gutter="20" justify="space-between">
    <Col span="8">
      <div >
<!--        <Scroll height="600px" >-->
          <Card >
            <div style="height: 600px;overflow: auto">
              <Tree :data="data6" :render="renderContent" :load-data="loadData" @on-select-change="getAreaInfo" class="demo-tree-render"></Tree>
            </div>
          </Card>
<!--        </Scroll>-->
      </div>
    </Col>
    <Col span="16">
      <Card>
        <Tabs type="card" :animated="false" @on-click="tabChange" v-model="tabIndex"  name="tab1" >
          <TabPane label="用户列表" name="list" tab="tab1">
            <Button type="primary" size="small" style="margin-bottom: 10px" @click="createCodeVisa()">添加</Button>
            <Table border :columns="columns12" :data="codeData">
              <template slot-scope="{ row, index }" slot="action">
                <Button type="primary" size="small" style="margin-right: 5px" @click="updateCode(row)">修改</Button>
              </template>
            </Table>
          </TabPane>
          <TabPane label="配置模板" name="visaList" v-if="tabShow===true" tab="tab1">
             <Tabs type="card"  v-model="visaIndex"  @on-click="visaTabChange" name="visaTab">
              <!-- <TabPane label="配置死亡证明模板" name="swList"  tab="visaTab">
                <Table border :columns="visaColumns" :data="swVisaData" :row-class-name="RowClassName">
                  <template slot-scope="{ row }" slot="compareNew">
                    <span>{{ row.new }}</span>
                  </template>
                  <template slot-scope="{ row }" slot="compareOld">
                    <span>{{ row.old }}</span>
                  </template>
                </Table>
              </TabPane> -->
              <TabPane label="配置居住证明模板" name="jzList"  tab="visaTab">
                 <Table border :columns="visaColumns" :data="VisaData" :row-class-name="RowClassName">
                   <template slot-scope="{ row }" slot="compareNew">
                     <span>{{row.new }}</span>
                   </template>
                   <template slot-scope="{ row }" slot="compareOld">
                     <span>{{ row.old }}</span>
                   </template>
                 </Table>
               </TabPane>
             </Tabs>
             <div style="display: flex;justify-content: right;margin-top: 10px">
               <Upload action="http://120.27.63.37:38081/api/ac/file/fileCommonService/upLoadFiles"  :before-upload="beforeUpload"  >
                 <Button icon="ios-cloud-upload-outline">上传文件</Button>
               </Upload>
               <Button icon="ios-cloud-upload-outline" @click="updateVis" style="margin-left: 20px">确认更新</Button>
             </div>
           </TabPane>
          <TabPane label="免密登陆" name="mianmi" tab="tab1">
            <div>
              <Form :model="yibaoItem" :label-width="100">
                <span>医保数据:</span>
                    <div>
                      <FormItem label="company_code">
                        <Input v-model="yibaoItem.company_code" placeholder=""></Input>
                      </FormItem>
                    </div>
                    <div>
                      <FormItem label="login_name">
                        <Input v-model="yibaoItem.login_name" placeholder=""></Input>
                      </FormItem>
                    </div>
                    <div>
                      <FormItem label="社区名称">
                      <Input v-model="yibaoItem.sqmc" placeholder=""></Input>
                      </FormItem>
                    </div>
                    <div>
                      <FormItem label="dwbh">
                      <Input v-model="yibaoItem.dwbh" placeholder=""></Input>
                      </FormItem>
                    </div>
                    <div>
                      <Button icon="ios-cloud-upload-outline"  @click="yibaoInsert" style="margin-left: 20px">创建数据</Button>
                      <Button icon="ios-cloud-upload-outline"  style="margin-left: 20px" @click="outUpdate">确认更新</Button>
                      <Button icon="ios-cloud-upload-outline" @click="yiBaoBySqmcList" style="margin-left: 20px" v-if="yibaoItem.buttonShow">查找数据</Button>
                    </div>
                    <div>

                  </div>

              </Form>
            </div>
          </TabPane>
          <!-- <TabPane label="社区编码" name="sqbm" v-if="tabShow===true" tab="tab1">
            <Form :model="sqItem" :label-width="100">
              <FormItem label="社区编码">
                <Row>
                  <Col span="10">
                    <Input v-model="sqItem.company_code" placeholder=""></Input>
                  </Col>
                </Row>
              </FormItem>
              <div>
                <Row>
                  <Col span="4" offset="5">
                    <Button  @click="sqCCodeInsert" style="margin-left: 20px">确定</Button>
                  </Col>
                </Row>
              </div>
            </Form>
          </TabPane> -->
<!--          <TabPane label="用户列表" name="list2" tab="tab1">-->
<!--            s-->
<!--            <div id="test" contenteditable style="width: 300px ; height: 300px ;border: red 1px ;background-color:black" @drop="dragover($event)"  ></div>-->
<!--          </TabPane>-->
        </Tabs>
      </Card>
    </Col>
  </Row>
  <Modal
    v-model="yibaoModal1"
    title="匹配社区"
  >
    <Table border :columns="yibaoColumns" :data="yibaoList" >
      <template slot-scope="{ row }" slot="action">
        <Button type="primary" size="small" style="margin-right: 5px" @click="update(row)">更新数据</Button>
      </template>
    </Table>
  </Modal>
  <Modal v-model="setcompanyinfo.isshow"
    title="设置机构"
    width="600"
    @on-ok="saveOption"
    @on-cancel="cancelOption">
    <Form label-position="left" :model="setcompanyinfo.data" :label-width="130">
      <FormItem v-show="hidden.super_name" label="上级机构：" v-if="setcompanyinfo.optionState === false">
          <Input v-model="setcompanyinfo.data.super_name" style="width: 70%" placeholder="必填" disabled></Input>
      </FormItem>
      <FormItem v-show="hidden.name" label="机构名称：">
          <Input v-model="setcompanyinfo.data.name" style="width: 70%" placeholder="必填"></Input>
      </FormItem>
      <FormItem v-show="hidden.code" label="机构编号：">
          <Input v-model="setcompanyinfo.data.code" style="width: 70%" placeholder="不填则自动生成"></Input>
      </FormItem>
      <FormItem v-show="hidden.code" label="社区编码：">
          <Input v-model="shequ_code" style="width: 70%" placeholder="社区编码"></Input>
      </FormItem>
      <FormItem v-show="hidden.sys_area" label="运营商编号：">
          <Select v-model="setcompanyinfo.data.sys_area" style="width: 70%" disabled>
              <Option value="LM">全市通办</Option>
          </Select>
      </FormItem>
      <slot v-show="hidden.slot" :row="setcompanyinfo.data"></slot>
      <FormItem v-show="hidden.area_id" label="归属区域：">
          <Select v-model="setcompanyinfo.data.area_id" style="width: 70%" filterable clearable>
              <Option v-for="item in cityList" :value="item.value" :key="item.value">{{ item.label }}
              </Option>
          </Select>
      </FormItem>
      <FormItem v-show="hidden.type" label="机构类型：">
          <Select v-model="setcompanyinfo.data.type" style="width: 70%" disabled>
              <Option value="1">公司</Option>
          </Select>
      </FormItem>
      <FormItem v-show="hidden.grade" label="机构等级：">
          <Select v-model="setcompanyinfo.data.grade" style="width: 70%" disabled>
              <Option value="1">一级</Option>
              <Option value="2">二级</Option>
              <Option value="3">三级</Option>
              <Option value="4">四级</Option>
              <Option value="5">五级</Option>
              <Option value="6">六级</Option>
              <Option value="7">七级</Option>
              <Option value="8">八级</Option>
              <Option value="9">九级</Option>
              <Option value="10">十级</Option>
          </Select>
      </FormItem>
      <FormItem v-show="hidden.useable" label="是否启用：">
          <i-switch v-model="setcompanyinfo.data.USEABLE" true-value="1" false-value="0" size="large">
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
          </i-switch>
      </FormItem>
      <FormItem v-show="hidden.address" label="联系地址：">
          <Input v-model="setcompanyinfo.data.address" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.zip_code" label="邮政编码：">
          <Input v-model="setcompanyinfo.data.zip_code" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.phone" label="电话：">
          <Input v-model="setcompanyinfo.data.phone" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.fax" label="传真：">
          <Input v-model="setcompanyinfo.data.fax" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.email" label="邮箱：">
          <Input v-model="setcompanyinfo.data.email" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.master" label="负责人：">
          <Input v-model="setcompanyinfo.data.master" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.primary_person" label="主负责人：">
          <Input v-model="setcompanyinfo.data.PRIMARY_PERSON" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.deputy_person" label="副负责人：">
          <Input v-model="setcompanyinfo.data.DEPUTY_PERSON" style="width: 70%"></Input>
      </FormItem>
      <FormItem v-show="hidden.sort" label="排序：">
          <InputNumber :min="0" v-model="setcompanyinfo.data.sort" style="width: 30%"></InputNumber>
      </FormItem>
      <FormItem v-show="hidden.remarks" label="备注信息：">
          <Input v-model="setcompanyinfo.data.remarks" maxlength="255" show-word-limit type="textarea"
                  :autosize="{minRows: 2,maxRows: 5}"></Input>
      </FormItem>
      <template v-if="setcompanyinfo.optionState === false">
          <FormItem v-show="hidden.role">
              <Checkbox size="large" v-model="roleState">勾选之后，会自动添加同名的用户。用户初始密码:qstb@2020，请尽快修改密码。</Checkbox>
          </FormItem>
          <FormItem v-show="hidden.role" label="用户角色：" v-if="roleState">
              <Tag v-for="item in roleList" size="medium" :checkable="true" :checked="false"
                    :key="item.id"
                    :name="item.name" @on-change="tagClick" style="cursor: pointer">{{ item.name }}
              </Tag>
          </FormItem>
      </template>
      <!-- <FormItem>
          <Button shape="circle" type="primary" :loading="btnLoading" @click="saveOption">保存</Button>
          <Button shape="circle" style="margin-left: 8px" @click="cancelOption">取消</Button>
      </FormItem> -->
    </Form>
  </Modal>
  <Modal v-model="asetuserinfo.isshow"
    title="设置用户"
    width="600"
    @on-ok="saveOptionUser"
    @on-cancel="cancelOptionUser">
    <Form ref="formItem" :rules="ruleValidate" label-position="right" :model="asetuserinfo.data" :label-width="120">
      <FormItem label="归属公司：">
          <Input v-model="asetuserinfo.data.company_name" disabled></Input>
      </FormItem>
      <FormItem label="登录手机号：" prop="mobile">
          <Input v-model="asetuserinfo.data.mobile" clearable placeholder="手机号码"></Input>
      </FormItem>
      <FormItem label="登录名：" v-show="asetuserinfo.optionState == true">
          <Input v-model="asetuserinfo.data.login_name" clearable placeholder="登录名" :disabled="asetuserinfo.optionState == true"></Input>
      </FormItem>
      <FormItem label="社区编码：" v-show="asetuserinfo.optionState == true">
          <Input v-model="shequ_code" clearable placeholder="社区编码" :disabled="asetuserinfo.optionState == true"></Input>
      </FormItem>
      <FormItem label="工号：" v-show="asetuserinfo.optionState == true">
          <Input v-model="asetuserinfo.data.no" clearable placeholder="工号"></Input>
      </FormItem>
      <FormItem label="姓名：" prop="name">
          <Input v-model="asetuserinfo.data.name" clearable placeholder="姓名"></Input>
      </FormItem>
      <FormItem label="密码：" prop="password">
          <Input v-model="asetuserinfo.data.password" clearable maxlength="20" type="password"
                  placeholder="密码"></Input>
          <span v-if="asetuserinfo.optionState == true" class="prompt-input">若不修改密码请留空</span>
      </FormItem>
      <FormItem label="确认密码：" prop="passwordc">
          <Input v-model="asetuserinfo.data.passwordc" clearable maxlength="20" type="password"
                  placeholder="确认密码"></Input>
      </FormItem>
      <FormItem label="邮箱：" prop="email">
          <Input v-model="asetuserinfo.data.email" clearable placeholder="邮箱"></Input>
      </FormItem>
      <FormItem label="电话：">
          <Input v-model="asetuserinfo.data.phone" clearable placeholder="电话"></Input>
      </FormItem>
      <FormItem label="允许登录：">
          <i-switch v-model="asetuserinfo.data.login_flag" true-value="1" false-value="0" size="large">
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
          </i-switch>
      </FormItem>
      <FormItem label="用户类型：">
          <Select v-model="asetuserinfo.data.user_type">
              <Option value="1">系统管理</Option>
              <Option value="2">部门经理</Option>
              <Option value="3">普通用户</Option>
              <Option value="9">接口对接</Option>
          </Select>
      </FormItem>
      <FormItem label="用户角色：">
          <CheckboxGroup v-model="currentRoleList">
              <Checkbox v-for="(item,index) in roleList" :key="index" :label="item.name" border>
                  {{item.name}}
              </Checkbox>
          </CheckboxGroup>
      </FormItem>
      <FormItem label="备注：">
          <Input v-model="asetuserinfo.data.remarks" type="textarea" maxlength="255" show-word-limit
                  :autosize="{minRows: 2,maxRows: 5}"/>
      </FormItem>
      <FormItem label="创建时间：" v-show="asetuserinfo.optionState == true">
          {{asetuserinfo.data.create_date}}
      </FormItem>
      <FormItem label="最后登录：" v-show="asetuserinfo.optionState == true">
          <div>
              <span style="font-weight: 600; margin-right: 5px">IP: </span>
              {{asetuserinfo.data.login_ip}}
          </div>
          <div>
              <span style="font-weight: 600; margin-right: 5px">时间: </span>
              {{asetuserinfo.data.login_date}}
          </div>
      </FormItem>
      <!-- <FormItem>
          <Button shape="circle" type="primary" :loading="btnLoading" @click="saveOptionUser">保存</Button>
          <Button shape="circle" style="margin-left: 8px" @click="cancelOptionUser">取消</Button>
      </FormItem> -->
    </Form>
  </Modal>
<!--  <Modal-->
<!--    v-model="modal1"-->
<!--    title="Common Modal dialog box title"-->
<!--    @on-ok="ok"-->
<!--    @on-cancel="cancel">-->
<!--    <Form ref="formInline" :model="userForm" :rules="ruleInline" >-->
<!--      <FormItem prop="user">-->
<!--        <Input type="text" v-model="userForm.user" placeholder="Username">-->
<!--          <Icon type="ios-person-outline" slot="prepend"></Icon>-->
<!--        </Input>-->
<!--      </FormItem>-->
<!--      <FormItem prop="手机号">-->
<!--        <Input type="手机号" v-model="userForm.mobile" placeholder="手机号">-->
<!--          <Icon type="ios-lock-outline" slot="prepend"></Icon>-->
<!--        </Input>-->
<!--      </FormItem>-->
<!--    </Form>-->
<!--  </Modal>-->
</div>
</template>

<script>
import { getAuditSysOfficeList, getAuditSysUserList, saveAuditSysUser, getAuditVisaList, updateAuditVisaInfo, saveAuditElectronicVisa, yiBaoByCompanyCodeList, yiBaoBySqmcList, updateYiBaoInfo, saveyiBaoInfo, createJieDaoSeQu } from '@/api/areaInfo'
import { getSign, createUpLoadFiles } from '@/api/common'
import { getCompanyRoleList, saveOfficeMZnew, getAreaList, getById, addUser,
  userIdGetAdminUserInfo, setUserInfo, getForUserList, selectAreacode } from '@/api/system/system'
export default {
  name: 'gpi',
  data () {
    const validateName = (rule, value, callback) => {
      if (!value) {
        callback(new Error('名称不能为空'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (!this.asetuserinfo.optionState) {
        if (!value) {
          callback(new Error('密码不能为空'))
        } else {
          if (!this.asetuserinfo.data.passwordc) {
            // 对第二个密码框单独验证
            this.$refs.asetuserinfo.data.validateField('passwordc')
          }
          callback()
        }
      } else {
        if (value) {
          if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/.test(value)) {
            callback(new Error('密码格式不正确（8-16位英文与数字组成）'))
          } else {
            if (!this.asetuserinfo.data.passwordc) {
              // 对第二个密码框单独验证
              this.$refs.asetuserinfo.data.validateField('passwordc')
            }
            callback()
          }
        }
        callback()
      }
    }
    const validatePasswordc = (rule, value, callback) => {
      if (!this.asetuserinfo.optionState) {
        if (!value) {
          callback(new Error('请再次输入密码'))
        } else if (value !== this.asetuserinfo.data.password) {
          callback(new Error('两次输入密码不一致'))
        } else {
          callback()
        }
      } else {
        if (this.asetuserinfo.data.password) {
          if (!value) {
            callback(new Error('请再次输入密码'))
          } else if (value !== this.asetuserinfo.data.password) {
            callback(new Error('两次输入密码不一致'))
          } else {
            callback()
          }
        } else {
          this.asetuserinfo.data.passwordc = null
        }
        callback()
      }
    }
    return {
      sqItem: {}, // 社区编码信息
      setcompanyinfo: {
        isshow: false,
        optionState: false,
        data: {
          USEABLE: '1',
          set_user: false,
          login_flag: '',
          area_id: '42',
          careacode: ''
        }
      },
      btnLoading: false,
      spinShow: false,
      cityList: [],
      roleList: [],
      roleState: false,
      hidden: {
        super_name: true,
        name: true,
        sys_area: true,
        slot: true,
        area_id: true,
        type: true,
        grade: true,
        useable: true,
        address: true,
        zip_code: true,
        phone: true,
        fax: true,
        email: true,
        master: true,
        primary_person: true,
        deputy_person: true,
        sort: true,
        remarks: true,
        role: true,
        code: true
      },
      asetuserinfo: {
        isshow: false,
        optionState: false,
        data: {}
      },
      ruleValidate: {
        name: [
          { required: true, validator: validateName, trigger: 'blur' }
        ],
        password: [
          { required: true, validator: validatePassword, trigger: 'blur' }
        ],
        passwordc: [
          { required: true, validator: validatePasswordc, trigger: 'blur' }
        ]
      },
      formItem: {},
      currentRoleList: [],
      upCpmpanyInfo: {},
      userForm: {
        user: '',
        mobile: ''
      },
      visaIndex: 'jzList',
      swVisaData: [],
      id: '',
      modalShow: false,
      data6: [],
      tabIndex: 0,
      columns12: [
        { title: '账号', key: 'login_name' },
        { title: '姓名', key: 'name' },
        { title: '手机号', key: 'mobile' },
        { title: 'Action', slot: 'action', width: 150, align: 'center' }
      ],
      visaColumns: [
        { title: '原信息', slot: 'compareOld', align: 'right' },
        { title: '对比值', key: 'key', width: 100, align: 'center' },
        { title: '新信息', slot: 'compareNew', align: 'left' }
      ],
      VisaData: [],
      codeData: [],
      tabShow: false,
      company_code: '',
      updateData: [],
      // 修改模板入参
      Obj: {},
      visCompany_code: '',
      Form_id: '',
      Item_id: '',
      street: '',
      community: '',
      county: '',
      // 医保免密登陆
      yibaoItem: {
        id: '',
        company_code: '',
        login_name: '',
        dwbh: '',
        sqmc: '',
        buttonShow: false
      },
      yibaoList: [],
      yibaoColumns: [
        { title: '社区名称', key: 'sqmc' },
        { title: 'Action', slot: 'action', width: 150, align: 'center' }
      ],
      sqmc: '',
      yibaoModal1: false,
      shequ_code: ''
    }
  },
  methods: {
    sqCCodeInsert () { // 给社区创建编码
      createJieDaoSeQu(this.sqItem).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '创建编码成功' })
        } else {
          this.$Notice.error({ title: '创建编码失败', desc: res.data.errmsg })
        }
      })
    },
    yibaoInsert () {
      saveyiBaoInfo(this.yibaoItem).then(res => {
        if (res.data.errcode === 0) {
          this.yiBaoByCompanyCodeList()
          this.$Notice.success({ title: '创建数据成功' })
        } else {
          this.$Notice.error({ title: '创建数据失败', desc: res.data.errmsg })
        }
      })
    },
    outUpdate () {
      updateYiBaoInfo(this.yibaoItem).then(res => {
        if (res.data.errcode === 0) {
          this.yiBaoByCompanyCodeList()
          this.$Notice.success({ title: '更新数据成功' })
        } else {
          this.$Notice.error({ title: '更新数据失败', desc: res.data.errmsg })
        }
      })
    },
    update (row) {
      let data = { id: row.id, company_code: this.visCompany_code }
      updateYiBaoInfo(data).then(res => {
        if (res.data.errcode === 0) {
          this.yiBaoByCompanyCodeList()
          this.yibaoModal1 = false
          this.$Notice.success({ title: '更新数据成功' })
        } else {
          this.$Notice.error({ title: '更新数据失败', desc: res.data.errmsg })
        }
      })
    },
    yiBaoBySqmcList () {
      let data = { sqmc: this.sqmc }
      yiBaoBySqmcList(data).then(res => {
        if (res.data.errcode === 0) {
          this.yibaoList = res.data.data
          this.yibaoModal1 = true
          console.log(res.data.data)
        }
      })
    },
    yiBaoByCompanyCodeList () {
      this.yibaoItem = {}
      let data = { company_code: this.visCompany_code }
      yiBaoByCompanyCodeList(data).then(res => {
        if (res.data.errcode === 0) {
          this.yibaoItem = res.data.data
        } else if (res.data.errmsg === '查询不到数据') {
          this.yibaoItem.buttonShow = true
        }
        console.log(res.data.data, 555)
        this.company_code = res.data.data.company_code
      })
    },
    dragover (e) {
      // e.stopPropagation()
      // e.preventDefault()
      // console.log(e)
      // const upBox = document.querySelector(e)
      // if (!upBox) { return }
      // upBox.addEventListener('dragover', dragoverFile)
      // upBox.addEventListener('drop', dropFile)
      // upBox.addEventListener('dragleave', dragleaveFile)
      // function dragoverFile (e) {
      //   e.preventDefault()
      // }
      // function dragleaveFile (e) {
      // }
      // function dropFile (e) {
      //   e.preventDefault()
      //   let fileList = e.dataTransfer.files
      //   let file = fileList[0]
      //   console.log(file)
      //   // 在这里就可以拿到拖拽的文件了，传到下一个函数进行处理
      //   // fileToBase64(file, callback)
      // }
    },

    RowClassName (row) {
      console.log(row.new === 'id')
      /* if (row.new !== row.old) {
        return 'demo-table-error-row'
      } else if (row.new === 'id') {
        console.log(554654646)
        return 'show'
      } else {
        return 'demo-table-info-row'
      } */
      if (row.new === 'id') {
        return 'show'
      } else if (row.new !== row.old) {
        return 'demo-table-error-row'
      } else {
        return 'demo-table-info-row'
      }
    },
    updateVis () {
      console.log(this.Obj, '修改入参')
      updateAuditVisaInfo(this.Obj).then(res => {
        if (res.data.errcode === 0) {
          let data = { company_code: this.visCompany_code }
          this.getAreaVis(data)
          this.$Notice.success({ title: '更新数据成功' })
        } else {
          this.$Notice.error({ title: '更新数据失败', desc: res.data.errmsg })
        }
      })
    },
    // 第二级别tab切换
    visaTabChange () {
      if (this.visaIndex === 'swList') {
        let swObj = {}
        if (this.swVisaData.length === 0) {
          this.id = '无信息'
        } else {
          this.id = this.swVisaData[0].id
          swObj = {
            catalogId: this.swVisaData[1].new,
            templateId: this.swVisaData[2].new,
            templateName: this.swVisaData[3].new,
            value: this.swVisaData[4].new,
            version: this.swVisaData[5].new,
            id: this.id,
            street: this.street,
            community: this.community,
            county: this.county
          }
        }
        this.Obj = swObj
        this.Item_id = '21210103001606506X5212000329000'
        this.Form_id = '178'
        this.Xml_id = 'siwangzhengming'
      }
      if (this.visaIndex === 'jzList') {
        let jzObj = {}
        if (this.VisaData.length === 0) {
          this.id = '无信息'
        } else {
          this.id = this.VisaData[0].id
          jzObj = {
            catalogId: this.VisaData[1].new,
            templateId: this.VisaData[2].new,
            templateName: this.VisaData[3].new,
            value: this.VisaData[4].new,
            version: this.VisaData[5].new,
            id: this.id,
            street: this.street,
            community: this.community,
            county: this.county
          }
        }
        this.Obj = jzObj
        this.Item_id = '11210103001606506X5212000329000'
        this.Form_id = '52'
        this.Xml_id = 'juzhuzhengmingVersion2'
      }
    },
    col (row) {
      // console.log(JSON.parse(JSON.stringify(row)) + 'sssss')
    },
    // 模板模态框ok事件
    visaClick () {

    },
    // 模板模态框close事件
    closeVisa () {},
    // 模板修改按钮
    updateCodeVisa (row) {
      this.visaShow.isshow = true
      this.company_code = row.company_code
      this.id = row.id
    //  console.log(this.id)
    },
    createCodeVisa () {
      if (!this.upCpmpanyInfo.id) {
        this.$Message.error({ content: '请先选择机构！' })
        return
      }
      let params = {
        company_id: this.upCpmpanyInfo.id
      }
      this.getRoleList(params)
      this.asetuserinfo = {
        isshow: true,
        optionState: false,
        data: {
          company_id: this.upCpmpanyInfo.id,
          company_name: this.upCpmpanyInfo.title
        }
      }
    },
    saveOptionUser () {
      this.$refs.formItem.validate((valid, callback) => {
        console.log(valid, 'valid=====,', this.asetuserinfo, 'this.asetuserinfo')
        if (!valid && !this.asetuserinfo.optionState) {
          this.$Message.error('请重新核查表单项!', callback)
          return
        }
        // 勾选角色列表数据处理
        let arr = []
        this.currentRoleList.forEach(item => {
          this.roleList.forEach(item1 => {
            if (item === item1.name) {
              arr.push(item1)
            }
          })
        })
        this.asetuserinfo.data.rolelist = arr
        this.asetuserinfo.data.careacode = this.shequ_code
        // 安全性处理
        console.log(this.asetuserinfo.optionState ? '添加' + this.asetuserinfo.optionState : '修改' + this.asetuserinfo.optionState)
        this.asetuserinfo.optionState ? this.updateUserAction(this.asetuserinfo.data) : this.addUserAction(this.asetuserinfo.data)
      })
    },
    addUserAction (data) {
      // 添加状态加上company_id
      data.company_id = this.upCpmpanyInfo.id
      // this.btnLoading = true
      addUser(data).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.$Modal.success({
            title: data.data.Message,
            content: '用户名：' + data.data.login_name
          })
          let param = {
            company_id: this.upCpmpanyInfo.id
          }
          console.log('当前选择机构', this.upCpmpanyInfo)
          this.codeInit(param)
          this.asetuserinfo.isshow = false
        } else {
          this.error(data)
        }
      })
    },
    updateUserAction (data) {
      setUserInfo(data).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.success()
          let param = {
            company_id: this.upCpmpanyInfo.id
          }
          console.log('当前选择机构', this.upCpmpanyInfo)
          this.codeInit(param)
          this.asetuserinfo.isshow = false
          this.asetuserinfo.optionState = true
        } else {
          this.error(data)
        }
      })
    },
    cancelOptionUser () {
      this.asetuserinfo.isshow = false
    },
    getUserInfoAction (data) {
      console.log(data, '修改用户data')
      data.contain_role = '1'
      userIdGetAdminUserInfo(data).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.asetuserinfo.data = data.data
          // 对已选中角色进行处理
          this.currentRoleList = []
          if (this.$common.xeUtils.isArray(this.asetuserinfo.data.rolelist)) {
            this.asetuserinfo.data.rolelist.forEach(item => {
              this.currentRoleList.push(item.name)
            })
          }
          this.asetuserinfo.isshow = true
          this.asetuserinfo.optionState = true
          this.getInfoByCode()
        } else {
          this.error(data)
        }
      })
    },
    getForUserListAction (param) {
      getForUserList(param).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.roleList = data.data
        } else {
          this.error(data)
        }
      })
    },
    success () {
      this.$Message.success('操作成功')
    },
    error (data) {
      this.$Message.error({
        content: '操作失败,\n' + data.errmsg
      })
    },
    // 上传图片前转base64
    beforeUpload (file) {
      //   console.log(this.visaIndex, 'innnn')
      // console.log(file)
      let upPicData = {
        filePath: 'DZzz/LM/' + this.visCompany_code,
        fileName: file.name + '.jpg'
      }
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        upPicData.file = reader.result.substring(index)
        this.upPic(upPicData)
      }
      return false
    },
    getAreaList () {
      getAreaList().then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          let cityData = []
          data.data.forEach(item => {
            cityData.push({ 'value': item.id, 'label': item.name })
          })
          this.cityList = cityData
        } else {
          this.error(data)
        }
      })
    },
    tagClick (checked, name, id) {
      this.roleList.forEach(item => {
        if (item.name === name) {
          checked === true ? item.state = true : item.state = false
        }
      })
    },
    getRoleList (data) {
      getCompanyRoleList(data).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.roleList = data.data
        } else {
          this.error(data)
        }
      })
    },
    cancelOption () {
      this.setcompanyinfo.isshow = false
    },
    saveOption () {
      // 添加机构用户绑定角色的处理
      if (this.setcompanyinfo.optionState === false) {
        let roleList = []
        this.roleList.forEach(item => {
          if (item.state !== undefined) {
            if (item.state === true) {
              roleList.push(item.id)
            }
          }
        })
        this.setcompanyinfo.data.rolelist = roleList
      }
      if (this.roleState === true) {
        this.setcompanyinfo.data.set_user = true
        this.setcompanyinfo.data.login_flag = '1'
      }
      this.setcompanyinfo.data.careacode = this.shequ_code
      this.setcompanyinfo.data.careacode = this.shequ_code
      // 保存操作
      saveOfficeMZnew(this.setcompanyinfo.data).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.$Message.success('操作成功')
          // 刷新机构列表
          let param = {
            grade: '3'
          }
          this.init(param)
          this.setcompanyinfo.isshow = false
        } else {
          this.error(data)
        }
      })
    },
    getById (data) {
      getById(data, undefined).then(ret => {
        let data = ret.data
        if (data.errcode === 0) {
          this.setcompanyinfo.data = {
            ...data.data,
            ...this.setcompanyinfo.data
          }
          this.setcompanyinfo.isshow = true
          this.getInfoByCode(data.code)
        } else {
          this.error(data)
        }
      })
    },
    getInfoByCode (company_code) {
      selectAreacode({ company_code: this.company_code }).then(ret => {
        console.log(ret, 'ret')
        if (ret.data.errcode === 0) {
          this.shequ_code = ret.data.data.shequ_code
          this.setcompanyinfo.data.careacode = ret.data.data.shequ_code
          this.asetuserinfo.data.careacode = ret.data.data.shequ_code
        } else {
          this.error(data)
        }
      })
    },
    // 上传图片
    upPic (obj) {
      let timeStep = new Date().getTime().toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: timeStep
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          let uploadParam = {
            sign: res.data.data.sign,
            timestamp: timeStep,
            filePath: obj.filePath,
            fileName: obj.fileName,
            file: obj.file
          }
          createUpLoadFiles(res.data.data.docking_url, uploadParam).then(res => {
            if (res.data.errcode === 0) {
              this.$Notice.success({ title: '上传图片成功' })
              if (this.id === '无信息') {
                let data = { company_code: this.visCompany_code,
                  form_id: this.Form_id,
                  item_id: this.Item_id,
                  xml_id: this.Xml_id,
                  xml_url: res.data.data
                }
                saveAuditElectronicVisa(data).then(res => {
                  if (res.data.errcode === 0) {
                    let datas = { company_code: this.visCompany_code }
                    this.getAreaVis(datas)
                    this.$Notice.success({ title: '新建数据成功' })
                  } else {
                    this.$Notice.error({ title: '新建数据失败', desc: res.data.errmsg })
                  }
                })
              } else {
                let data = { id: this.id, xml_url: res.data.data }
                updateAuditVisaInfo(data).then(res => {
                  let data = { company_code: this.visCompany_code }
                  if (res.data.errcode === 0) {
                    this.$Notice.success({ title: '更改图片信息成功' })
                  } else {
                    this.$Notice.error({ title: '更改图片信息失败', desc: res.data.errmsg })
                  }
                  this.getAreaVis(data)
                })
              }
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.errmsg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.errmsg })
        }
      })
    },
    renderContent (h, { root, node, data }) {
      let gradename = ''
      if (data.grade !== undefined) {
        if (data.grade === '3') {
          gradename = '区县'
        } else if (data.grade === '4' && data.type === '1') {
          gradename = '街道'
        } else if (data.grade === '4' && data.type === '2') {
          gradename = '乡镇'
        } else if (data.grade === '5' && data.type === '1') {
          gradename = '社区'
        } else if (data.grade === '5' && data.type === '2') {
          gradename = '农村'
        }
      }
      return h('span', {
        style: {
          display: 'inline-block',
          width: '100%'
        }
      }, [
        h('span', [
          h('span', gradename),
          h('Icon', {
            props: {
              type: 'ios-paper-outline'
            },
            style: {
              marginRight: '8px'
            }
          }),
          h('span', data.title),
          // h('Button', {
          //   props: { type: 'success', size: 'small' },
          //   style: { marginLeft: '30px' },
          //   icon: 'md-add',
          //   on: {
          //     click: () => {
          //       console.log(data, '添加')
          //     }
          //   }
          // }, '添加'),
          h('Icon', {
            props: {
              type: 'md-add' // iview自带的删除icon
            },
            style: {
              marginLeft: '30px'
            },
            on: {
              click: () => {
                let params = {
                  company_id: data.id
                }
                this.getRoleList(params)
                this.getAreaList()
                let downgrade = '3'
                if (data.grade !== undefined) {
                  if (data.grade === '3') {
                    downgrade = '4'
                  } else if (data.grade === '4') {
                    downgrade = '5'
                  } else if (data.grade === '5') {
                    downgrade = '5'
                  }
                }
                this.setcompanyinfo = {
                  isshow: false,
                  optionState: false,
                  data: {
                    USEABLE: '1',
                    set_user: false,
                    login_flag: '',
                    area_id: '42',
                    super_name: data.title,
                    parent_id: data.id,
                    sys_area: 'LM',
                    type: '1',
                    grade: downgrade,
                    sort: 100
                  }
                }
                // this.setcompanyinfo.data = {
                //   USEABLE: '1',
                //   set_user: false,
                //   login_flag: '',
                //   area_id: '42',
                //   super_name: data.title,
                //   parent_id: data.id,
                //   sys_area: 'LM',
                //   type: '1',
                //   grade: downgrade,
                //   sort: '100'
                // }
                this.setcompanyinfo.isshow = true
                console.log(data, '点击了+') // 点击操作事件
              }
            }
          }),
          h('Icon', {
            props: {
              type: 'ios-create-outline' // iview自带的删除icon
            },
            style: {
              marginLeft: '30px'
            },
            on: {
              click: () => {
                this.setcompanyinfo = {
                  isshow: false,
                  optionState: true,
                  data: {
                    USEABLE: '1',
                    set_user: false,
                    login_flag: '',
                    area_id: '42'
                  }
                }
                this.roleState = false
                let params = {
                  company_id: data.id
                }
                this.getRoleList(params)
                this.getAreaList()
                this.company_code = data.code
                this.getById(data)
                console.log(data, '点击了edit') // 点击操作事件
                console.log(this.company_code, 'this.company_code')
              }
            }
          })
        ])/*,
        h('span', {
          style: {
            display: 'inline-block',
            float: 'right',
            marginRight: '32px'
          }
        }, [
          h('Button', {
            props: Object.assign({}, this.buttonProps, {
              icon: 'ios-add'
            }),
            style: {
              marginRight: '8px'
            },
            on: {
              click: () => { this.append(data) }
            }
          }),
          h('Button', {
            props: Object.assign({}, this.buttonProps, {
              icon: 'ios-remove'
            }),
            on: {
              click: () => { this.remove(root, node, data) }
            }
          })
        ]) */
      ])
    },
    append (data) {
      const children = data.children || []
      children.push({
        title: 'appended node',
        expand: true
      })
      this.$set(data, 'children', children)
    },
    remove (root, node, data) {
      const parentKey = root.find(el => el === node).parent
      const parent = root.find(el => el.nodeKey === parentKey).node
      const index = parent.children.indexOf(data)
      parent.children.splice(index, 1)
    },
    init (param) {
      getAuditSysOfficeList(param).then(ret => {
        //   console.log(ret.data.errcode)
        if (ret.data.errcode === 0) {
          this.data6 = this.getTree(ret.data.data.result)
        }
      })
    },
    codeInit (param) {
      getAuditSysUserList(param).then(ret => {
        //   console.log(ret.data.errcode)
        if (ret.data.errcode === 0) {
          this.codeData = ret.data.data.result
        }
      })
    },
    getTree (tree) {
      //  console.log(tree)
      let arr = []
      tree.forEach(item => {
        let obj = {
          title: item.name,
          id: item.id,
          parent_ids: item.parent_ids,
          grade: item.grade,
          code: item.code,
          children: [],
          loading: false,
          type: item.type
        }
        arr.push(obj)
      })
      //  console.log(arr)
      return arr
    },
    loadData (item, callback) {
      let param = {
        grade: parseInt(item.grade) + 1,
        parent_ids: item.parent_ids + item.id + ','
      }
      if (item.grade === '3') {
        this.county = item.title
      } else if (item.grade === '4') {
        this.street = item.title
      }
      let data = []
      getAuditSysOfficeList(param).then(ret => {
      //  console.log(ret.data.errcode)
        if (ret.data.errcode === 0) {
          data = this.getTree(ret.data.data.result)
          callback(data)
        }
      })
    },
    tabChange () {

    },
    removeCode () {

    },
    updateCode (data) {
      // this.modalShow = true
      // console.log(data)
      // updateAuditSysUserInfo(param).then(ret => {
      //   console.log(ret.data.errcode)
      //   if (ret.data.errcode === 0) {
      //     this.data6 = this.getTree(ret.data.data.result)
      //   }
      // })
      let params = {
        company_id: this.upCpmpanyInfo.id
      }
      this.getRoleList(params)
      this.getUserInfoAction(data)
    },
    getAreaInfo (val) {
      if (val.length < 1) {
        return
      }
      let grade = val[0].grade
      this.grade = grade
      this.community = val[0].title
      if (val[0].title.toString().indexOf('街道') !== -1) {
        let index = val[0].title.toString().lastIndexOf('街道')
        let end = val[0].title.toString().length
        this.sqmc = val[0].title.toString().substring(index + 2, end)
      } else {
        this.sqmc = val[0].title.toString()
      }
      if (grade === '5') {
        let data = { company_code: val[0].code }
        this.visCompany_code = val[0].code
        this.getAreaVis(data)
        this.tabShow = true
        this.yiBaoByCompanyCodeList()
      }
      let param = {
        company_id: val[0].id
      }
      this.upCpmpanyInfo = val[0]
      console.log('当前选择机构', this.upCpmpanyInfo)
      this.codeInit(param)
    },
    addCode () {
      saveAuditSysUser(param).then(ret => {
        if (ret.data.errcode === 0) {
          this.data6 = this.getTree(ret.data.data.result)
        }
      })
    },
    getAreaVis (data) {
      this.VisaData = []
      this.swVisaData = []
      getAuditVisaList(data).then(res => {
        let temp = res.data.data.result
        temp.forEach((item) => {
          if (item.item.form_id === '52') {
            this.VisaData = []
            this.VisaData.push({ id: item.item.id, new: 'id' })
            this.VisaData.push({ id: 0, key: 'catalog_id', new: item.xml_map.catalogId, old: item.item.catalog_id })
            this.VisaData.push({ id: 1, key: 'template_id', new: item.xml_map.templateId, old: item.item.template_id })
            this.VisaData.push({ id: 2, key: 'template_name', new: item.xml_map.templateName, old: item.item.template_name })
            this.VisaData.push({ id: 3, key: '区域', new: item.xml_map.value, old: item.item.issue_unitname })
            this.VisaData.push({ id: 4, key: '版本', new: item.xml_map.version, old: item.item.version })
          }
          if (item.item.form_id === '178') {
            this.swVisaData = []
            this.swVisaData.push({ id: item.item.id, new: 'id' })
            this.swVisaData.push({ id: 0, key: 'catalog_id', new: item.xml_map.catalogId, old: item.item.catalog_id })
            this.swVisaData.push({ id: 1, key: 'template_id', new: item.xml_map.templateId, old: item.item.template_id })
            this.swVisaData.push({ id: 2, key: 'template_name', new: item.xml_map.templateName, old: item.item.template_name })
            this.swVisaData.push({ id: 3, key: '区域', new: item.xml_map.value, old: item.item.issue_unitname })
            this.swVisaData.push({ id: 4, key: '版本', new: item.xml_map.version, old: item.item.version })
          }
        })
        this.visaTabChange(this.visaIndex)
      })
    }
  },
  mounted () {
    let param = {
      grade: '3'
    }
    this.init(param)
  }
}
</script>

<style >
  .ivu-table .demo-table-info-row td{
    background-color: white;
    color: #515A6E;
  }
  .ivu-table .demo-table-error-row td{
    background-color: #F0F8FF;
    color: #5d6c7b;
  }
  .ivu-table .show td{
    display: none;
  }
</style>
